import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';

@Injectable()
export class GzwzxzFrmControllerService {
  private frameCode = "5iz4";
  private frameId = "gzwzxz-" + this.frameCode + "-component_gzwzxz_data-grid-component";
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) {}

  /**
   * 报废物资选择
   * @remarks 
   * @returns 
   */
  bfwzxz(): any {
      console.log('viewInitEvent:', this.frameContext.appContext.frameContextManager);
      const uiState = this.frameContext.uiState;
      const checkeds = this.frameContext.appContext.componentManager.get([this.frameId, 'dataGrid']).checkeds;
      console.log('checkeds:', checkeds);
      if(checkeds.length == 0) {
        this.messageService.warning('请选择一条数据！');
        return EMPTY;
      }
      let data: string[] = [];
      for(let item of checkeds){
        data.push(item.data);
      }
      uiState.setPropertyValue('selectData', data);
      this.commandService.execute('rootClose1');
  }
}
